<template>
  <el-dialog :visible.sync="isShow" width="1000px" title="分配教师">
    <el-row>
      <el-form :model="searchParams" ref="searchParams" :inline="true">
        <el-form-item label="姓名">
          <el-input class="input" v-model="searchParams.realname" maxlength='20' placeholder="请输入" clearable
            show-word-limit></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="handleSearch" type="primary" icon="el-icon-search" style="margin-left:40px">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-form :inline="true" style="margin:10px 0">
        <el-button @click="operateAction('create', {})" type="primary" plain size='small'>新增</el-button>
        <el-button @click="operateAction('delete', {})" type="info" plain size='small'>删除</el-button>
      </el-form>
      <el-table :data="dataList" size='medium' ref="multipleTable" border>
        <el-table-column width="80" label="教师ID">
          <template slot-scope="{row, index}">
            <el-radio v-model="radio" :label="row.id">{{ row.id }}</el-radio>
          </template>
        </el-table-column>
        <el-table-column prop="typesLabel" label="类型" show-overflow-tooltip></el-table-column>
        <el-table-column prop="userModel.username" label="用户名" show-overflow-tooltip></el-table-column>
        <el-table-column prop="school_name" label="学校" show-overflow-tooltip></el-table-column>
        <el-table-column prop="dept_name" label="系部" show-overflow-tooltip></el-table-column>
        <el-table-column prop="realname" label="姓名" show-overflow-tooltip></el-table-column>
        <el-table-column prop="id_card" label="身份证号" show-overflow-tooltip></el-table-column>
        <el-table-column prop="phone" label="电话" show-overflow-tooltip></el-table-column>
        <el-table-column prop="checkStatus" label="审核状态" show-overflow-tooltip>
          <template slot-scope="{row, index}">
            <el-tag v-if="row.checkStatus == 'PASS'">通过</el-tag>
            <el-tag v-if="row.checkStatus == 'REFUSE'" type="info">未通过</el-tag>
            <el-tag v-if="row.checkStatus == 'CHECKING'" type="success">审核中</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" show-overflow-tooltip></el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="200">
          <template slot-scope="{row, index}">
            {{ formatTime.dateFormat('YY-MM-DD hh:mm:ss', row.createTime) }}
          </template>
        </el-table-column>
      </el-table>
      <pagination style="background: #ffffff; height: 50px" v-show="totalSize > 0" :total="totalSize" :page.sync="page"
        :limit.sync="size" @pagination="getDataList" />
    </el-row>
    <div style="margin-top: 30px;width: 100%;display: flex;flex-direction: row;justify-content: flex-end;">
      <el-button type="primary" @click="confirm">确认</el-button>
      <el-button @click="close" type="info" size="mini">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { formData } from './data'

export default {
  components: {
  },
  props: {

  },
  data() {
    return {
      isShow: false,
      page: 1,
      size: 10,
      totalSize: 0,
      searchParams: {},
      dataList: [],
      radio: '',
      formData,
      row: {}
    }
  },
  created() {
    this.getDataList()
  },
  methods: {
    show(val) {
      this.isShow = true
      this.row = val
      if (val.teacher) {
        this.radio = val.teacher
      }
    },
    close() {
      this.isShow = false
    },
    confirm() {
      if (!this.radio) {
        this.$message({
          message: '请选择记录',
          type: 'error'
        })
        return
      }
      this.request_post(this.formData.updateUrl, { obj_id: this.row.id, teacher: this.radio }).then(res => {
        if (res.data.code == 10000) {
          this.$emit('confirm', this.radio)
          this.isShow = false
        }
      });
    },
    handleSearch() {
      this.page = 1
      this.getDataList()
    },
    // 获取列表数据
    getDataList() {
      this.searchParams.page = this.page
      this.searchParams.size = this.size
      this.searchParams.checkStatus = "PASS"
      this.request_get('education/teacher/', this.searchParams).then(res => {
        if (res.data.code == 10000) {
          this.totalSize = res.data.data.total_count
          this.dataList = res.data.data.list
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped></style>